package iset.coverageanalyzer.output;

import iset.coverageanalyzer.misc.KeyValuePair;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Properties;

public class JPFGenerator {
	
	public static void generate(String dstJPFFile, JPFInfo jpfInfo) throws IOException{
		/*
		Properties p = new Properties();
		handle(p,jpfInfo);
		FileOutputStream os = new FileOutputStream(dstJPFFile);
		String description = "store properties to test.jpf";
		p.store(os, description);
		os.close();
		*/
		
		PrintWriter pw = new PrintWriter(dstJPFFile);
		
		KeyValuePair kvp = null;
		for(int i=0;i< jpfInfo.getSize();i++){
			kvp = jpfInfo.getKVP(i);
			pw.println(kvp.key+"="+kvp.value);
		}
		pw.close();
	}
	
	private static void handle(Properties p, JPFInfo info){
		KeyValuePair kvp = null;
		for(int i=0;i<info.getSize();i++){
			kvp = info.getKVP(i);
			p.put(kvp.key, kvp.value);
		}
	}
	
	// for testing
	public static void main(String[] args){
		JPFInfo jpfinfo = new JPFInfo();
		jpfinfo.addKeyValue("target", "examples.Example");
		jpfinfo.addKeyValue("symbolic.method", "examples.Example.foo(sym#con)");
		jpfinfo.addKeyValue("listener", "gov.nasa.jpf.symbc.SymbolicListener");
		jpfinfo.addKeyValue("vm.storage.class", "nil");
		jpfinfo.addKeyValue("search.multiple_errors", "true");
		
		try {
			generate("xiaomaolv.jpf",jpfinfo);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
